package com.gzxt.agricultural.service;

import com.gzxt.agricultural.utils.WeBASEUtils;
import com.gzxt.agricultural.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class TraceServiceImpl implements TraceService {
    @Value("${system.contract.owner_address}")
    private String owner_address;
    @Autowired
    private WeBASEUtils weBASEUtils;

    @Override
    public Result getTraceInfo(int traceNumber) {
        //加入一些条件判断traceNumber是一个大于0的值
        if(traceNumber<0){
            return Result.error(500,"参数不合法");
        }
        List funcParam = new ArrayList();
        funcParam.add(1);//变量traceNumber 1
        String result = weBASEUtils.funcPost(owner_address, "getTraceInfo", funcParam);
        return Result.success(result);
    }

    @Override
    public Result getAllFood() {
        List funcParam = new ArrayList();
        //第一个参数 代表谁（那个用户地址）在调用函数 2.合约里面的函数名称 3.传递给函数的参数
        String result = weBASEUtils.funcPost(owner_address, "getAllFood", funcParam);
        return Result.success(result);
    }

    @Override
    public Result getFood(int traceNumber) {
        //加入一些条件判断traceNumber是一个大于0的值
        if(traceNumber<0){
            return Result.error(500,"参数不合法");
        }
        List funcParam = new ArrayList();
        funcParam.add(1);//变量traceNumber 1
        String result = weBASEUtils.funcPost(owner_address, "getFood", funcParam);
        return Result.success(result);
    }
}
